package com.kyh.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

public abstract class MethodUtil {
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	
	private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
	
	/*
	 * 创建还款订单号
	 */
	public static String createOrdernumForRepay(){
		return "hk" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建升级币转现金订单号
	 */
	public static String createOrdernumForCoinToCash() {
		return "ctc" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建认证订单号
	 */
	public static String createOrdernumForAuthenPost() {
		return "rz" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建刷卡订单号
	 */
	public static String createOrdernumForSwing() {
		return "sk" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建升级订单号
	 */
	public static String createOrdernumForUpgrade() {
		return "sj" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建提现代付订单号
	 */
	public static String createOrderNoDaifuForWithdraw() {
		return "DFWT1" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建系统提现代付订单号
	 */
	public static String createOrderNoDaifuForWithdrawSystem() {
		return "DFWS" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建交易流水号
	 */
	public static String createOrderNoForTransOrder() {
		return "TO" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建规划流水号
	 */
	public static String createOrderNoForScheme() {
		return "GH" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建规划详情流水号
	 */
	public static String createOrderNoForSchemeRunning() {
		return "GHXQ" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建畅捷碰一碰入驻订单号
	 */
	public static String createOrdernumForCjPengToPeng() {
		return "CJPPSI" + sdf.format(new Date()) + createRandomNumCode(2);
	}
	
	/*
	 * 创建交易流水号（商户入驻）
	 */
	public static String createOrderNoForStoreIn() {
		return "TO" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建商城总订单编号
	 */
	public static String createOrderNoForShoppingOrderManager() {
		return "SMO" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建商城订单编号
	 */
	public static String createOrderNoForShoppingOrder() {
		return "SOR" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 创建商城订单详情编号
	 */
	public static String createOrderNoForShoppingOrderDetail() {
		return "SOD" + sdf.format(new Date()) + createRandomNumCode(3);
	}
	
	/*
	 * 生成文件相对目录
	 */
	public static String createPathRelativeUpload(Date now) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		return "common/upload/" + sdf.format(now);
	}
	
	/*
	 * 生成随机验证码
	 */
	public static String createRandomNumCode(int length) {
		String code = "";
		for (int i = 0; i < length; i++) {
			int c = (int) (Math.random() * 10);
			code += c;
		}
		return code;
	}
	
	/**
	 * 获取唯一随机数  时间戳+2位数字
	 * @return
	 */
	public static String createUniqueRandom() {
		return System.currentTimeMillis() + MethodUtil.createRandomNumCode(2);
	}
	
	/*
	 * 获取项目路径
	 */
	public static String getWebPath(HttpServletRequest request) {
		String requestUrl = request.getRequestURL().toString();
		String projectName =request.getContextPath();
		
		int indexOfProjectName = requestUrl.indexOf(projectName);
		return requestUrl.substring(0, indexOfProjectName) + projectName;
	}
	
	/*
	 * 获取项目路径
	 */
	public static String getTimeStr(long nowtime, long datatime) {
		long timediff = nowtime - datatime;
		String timeStr = "";
		if (timediff < 60 * 1000L) {
			timeStr = "刚刚";
		} else if (timediff < 60 * 60 * 1000L) {
			timeStr = timediff/60000L + "分钟前";
		} else if (timediff < 24 * 60 * 60 * 1000L) {
			timeStr = timediff/3600000L + "小时前";
		} else if (timediff < 2 * 24 * 60 * 60 * 1000L) {
			timeStr = "1天前";
		} else if (timediff < 3 * 24 * 60 * 60 * 1000L) {
			timeStr = "2天前";
		} else if (timediff < 4 * 24 * 60 * 60 * 1000L) {
			timeStr = "2天前";
		} else if (timediff < 5 * 24 * 60 * 60 * 1000L) {
			timeStr = "4天前";
		} else if (timediff < 6 * 24 * 60 * 60 * 1000L) {
			timeStr = "5天前";
		} else if (timediff < 7 * 24 * 60 * 60 * 1000L) {
			timeStr = "6天前";
		} else {
			timeStr = sdf2.format(new Date(datatime));
		}
		
		return timeStr;
	}
	
	public static void main(String[] args) {
	}
}
